<CFQUERY NAME="activityoverride" DATASOURCE="#client.company_dsn#">
	SELECT ACTIVITYID, MAPPING, ROLECODE
	FROM CINFFACTIVITY
	WHERE (PROCESSCODE = '#theProcess#')
	ORDER BY ORDERID
</CFQUERY>

<CFLOOP QUERY="activityoverride">
	<!--- Override mapping is for userrole only --->
	<CFIF LCase(activityoverride.MAPPING) IS "userrole">
		<CFOUTPUT>
			<CFSET sValidActivityID=Replace(activityoverride.ACTIVITYID, "-", "", "ALL")>

			<CFIF IsDefined("form.hidden#sValidActivityID#")>
				<CFSET sUserID=Trim(Evaluate("form.hidden#sValidActivityID#"))>

				<CFIF sUserID IS NOT "">
					<!--- Delete existing record --->
					<CFQUERY DATASOURCE="#client.company_dsn#" NAME="deletexist">
						DELETE
						FROM ECMFUSRDEFINEROLE
						WHERE ROUTEID = '#sRouteID#' AND
							  ACTIVITYID = '#activityoverride.ACTIVITYID#'
					</CFQUERY>
					<!--- Insert new override --->
					<CFQUERY DATASOURCE="#client.company_dsn#" NAME="insertoverride">
						INSERT INTO ECMFUSRDEFINEROLE(ROUTEID, ACTIVITYID, USERID)
						VALUES('#sRouteID#', '#activityoverride.ACTIVITYID#', '#sUserID#')
					</CFQUERY>
				</CFIF>
			<CFELSEIF IsDefined("client.sCode2Use")>
				<CFSET sUserID=Trim("#client.sCode2Use#")>

				<CFIF sUserID IS NOT "">
					<!--- Delete existing record --->
					<CFQUERY DATASOURCE="#client.company_dsn#" NAME="deletexist">
						DELETE
						FROM ECMFUSRDEFINEROLE
						WHERE ROUTEID = '#sRouteID#' AND
							  ACTIVITYID = '#activityoverride.ACTIVITYID#'
					</CFQUERY>
					<!--- Insert new override --->
					<CFQUERY DATASOURCE="#client.company_dsn#" NAME="insertoverride">
						INSERT INTO ECMFUSRDEFINEROLE(ROUTEID, ACTIVITYID, USERID)
						VALUES('#sRouteID#', '#activityoverride.ACTIVITYID#', '#sUserID#')
					</CFQUERY>
				</CFIF>

			</CFIF> <!--- Check form variable --->
		</CFOUTPUT>
	</CFIF> <!--- For Userrole only --->
</CFLOOP> <!--- Loop Activity --->